attribute vec3 aPosition;
attribute vec3 aNormal;
attribute vec3 aTangent;
attribute vec2 aTex;

uniform vec3 uLightPos;			//	light position in eye space
uniform mat4 uModelViewMatrix;	//	
uniform mat4 uNormalMatrix;		//	
uniform mat4 uProjectionMatrix;	//	
	
varying vec3 pEyeVec;			//	vertex_to_eye vector (in TBN space)
varying vec3 pLightDir;			//	light_to_vertex vector  (in TBN space)
varying vec2 pTexCoord;			//	texture coordinate

void main()
{
	vec3 n = (uNormalMatrix * vec4(aNormal, 0.0)).xyz;
	vec3 t = (uNormalMatrix * vec4(aTangent, 0.0)).xyz;
	vec3 b = cross(n, t);
	
	vec3 vertexPos = (uModelViewMatrix * vec4(aPosition, 1.0)).xyz;
	
	pLightDir = vec3(dot(t, vertexPos - uLightPos), dot(b, vertexPos - uLightPos), dot(n, vertexPos - uLightPos));
	
	pEyeVec = vec3(dot(t, 0 - vertexPos), dot(b, 0 - vertexPos), dot(n, 0 - vertexPos));
	
	pTexCoord = aTex;
	
	gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aPosition, 1.0);
}
